﻿

    using Maticsoft.BLL;
    using Maticsoft.Model;

    using System;
    using System.Text;
    using System.Web;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;

    public partial class WebPage_YingXiao_ShujuXiazai_Email : MarketBBasePage
    {

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            this.HeaderControl1.Select = "yingxiao";
            this.YingXiao1.Select = "shuju";
            if (!base.IsPostBack)
            {
                this.setEmail();
            }
            if (base.Request.HttpMethod == "POST")
            {
                if ((base.Request.Form["city_id"] != null) && (base.Request.Form["source[]"] != null))
                {
                    string citys = base.Request.Form["city_id"].ToString();
                    string type = base.Request.Form["source[]"].ToString();
                    this.xiazai(citys, type);
                }
                else
                {
                    this.SetError("-ERR ERR_NO_DATA");
                    base.Response.Redirect("YingXiao_ShujuXiazai_Email.aspx");
                }
            }
        }

        private void setEmail()
        {
            StringBuilder builder = new StringBuilder();
            Maticsoft.BLL.Category category = new Maticsoft.BLL.Category();
            foreach (Maticsoft.Model.Category category2 in category.GetModelList("Zone='city'"))
            {
                builder.Append(string.Concat(new object[] { "<input type='checkbox' name='city_id' value='", category2.Id, "' checked />&nbsp;", category2.Name, "&nbsp;&nbsp;" }));
            }
            this.Literal1.Text = builder.ToString();
        }

        private void xiazai(string citys, string type)
        {
            StringBuilder builder = new StringBuilder();
            int num = 1;
            if ((citys == "") || (type == ""))
            {
                this.SetError("-ERR ERR_NO_DATA");
                base.Response.Redirect("YingXiao_ShujuXiazai_Email.aspx");
            }
            else
            {
                builder.Append("<html>");
                builder.Append("<meta http-equiv=content-type content=\"text/html; charset=UTF-8\">");
                builder.Append("<body><table border='1'>");
                builder.Append("<tr>");
                builder.Append("<td>ID</td>");
                builder.Append("<td>用户Email</td>");
                builder.Append("</tr>");
                if (type.IndexOf("user") >= 0)
                {
                    Maticsoft.BLL.UserInfo info = new Maticsoft.BLL.UserInfo();
                    foreach (Maticsoft.Model.UserInfo info2 in info.GetModelList("City_id in (" + citys + ")"))
                    {
                        builder.Append("<tr>");
                        int num2 = num++;
                        builder.Append("<td align='left'>" + num2.ToString() + "</td>");
                        builder.Append("<td align='left'>" + info2.Email + "</td>");
                        builder.Append("</tr>");
                    }
                }
                if (type.IndexOf("subscribe") >= 0)
                {
                    Maticsoft.BLL.Mailer mailer = new Maticsoft.BLL.Mailer();
                    foreach (Maticsoft.Model.Mailer mailer2 in mailer.GetModelList("city_id in (" + citys + ")"))
                    {
                        builder.Append("<tr>");
                        builder.Append("<td align='left'>" + num++.ToString() + "</td>");
                        builder.Append("<td align='left'>" + mailer2.Email + "</td>");
                        builder.Append("</tr>");
                    }
                }
                builder.Append("</table></body></html>");
                base.Response.ClearHeaders();
                base.Response.Clear();
                base.Response.Expires = 0;
                base.Response.Buffer = true;
                base.Response.AddHeader("Accept-Language", "zh-tw");
                base.Response.AddHeader("content-disposition", "attachment; filename=" + HttpUtility.UrlEncode("Eamil_" + DateTime.Now.ToString("yyyy-MM-dd") + ".xls", Encoding.UTF8));
                base.Response.ContentType = "Application/octet-stream";
                base.Response.Write(builder.ToString());
                base.Response.End();
            }
        }
    }


